package com.qingke.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.DetachedCriteria;

import com.qingke.hibernate.bean.Student;

public class CriteriaDemo {
	public static void main(String[] args){
		try{
			SessionFactory sf=new Configuration().configure().buildSessionFactory();
			Session session=sf.openSession();
			
			Criteria criteria=session.createCriteria(Student.class);
			List<?>  students1=criteria.list();
			for(Object o:students1){
				System.out.println(o);
			}
			
			
			System.out.println("=======================");
			
			DetachedCriteria detachCriteria=DetachedCriteria.forClass(Student.class);
			Criteria c=detachCriteria.getExecutableCriteria(session);
			List<?>  students2=c.list();
			for(Object o:students2){
				System.out.println(o);
			}
		
		}catch(HibernateException e){
			e.printStackTrace();
		}
		
	}
}
